//
//  ADNaviDriveView.m
//  Anda_Driver_Pro
//
//  Created by AnDa-Y on 2019/7/12.
//  Copyright © 2019 AnDa-Y. All rights reserved.
//

#import "ADNaviDriveView.h"

@implementation ADNaviDriveView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self initMapView];
    }
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self initMapView];
}

- (void)initMapView {
    UIView *driveView = nil;
    driveView = [[AMapNaviDriveView alloc] init];
    self.aDriveView = (AMapNaviDriveView *)driveView;
    self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.showType = ADNaviDriveViewTypeMap;
    [self addSubview:driveView];
    
    self.aDriveView.translatesAutoresizingMaskIntoConstraints = NO;
    NSLayoutConstraint *left = [self.aDriveView.leftAnchor constraintEqualToAnchor:self.leftAnchor];
    NSLayoutConstraint *rignt = [self.aDriveView.rightAnchor constraintEqualToAnchor:self.rightAnchor];
    NSLayoutConstraint *top = [self.aDriveView.topAnchor constraintEqualToAnchor:self.topAnchor];
    NSLayoutConstraint *bottom = [self.aDriveView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor];
    [NSLayoutConstraint activateConstraints:@[left, rignt, top, bottom]];
}

- (void)setShowRoute:(BOOL)showRoute
{
    self.aDriveView.showRoute = showRoute;
}

- (void)setShowType:(ADNaviDriveViewType)showType
{
    _showType = showType;
    
    self.aDriveView.showVectorline = NO;
    [self.aDriveView setCarImage:[UIImage imageNamed:@"icon_car"]];
    
    if (showType == ADNaviDriveViewTypeNavi) {
        [self.aDriveView setShowCamera:YES]; // 是否显示摄像头,默认YES
        [self.aDriveView setShowMode:AMapNaviDriveViewShowModeOverview]; // 导航界面显示模式,默认AMapNaviDriveViewShowModeCarPositionLocked 1: 锁车状态 , 2: 全览状态 , 3: 普通状态
        
        [self.aDriveView setTrackingMode:(AMapNaviViewTrackingModeCarNorth)];
        [self.aDriveView setShowCompass:YES]; // 是否显示指南针,默认NO
        [self.aDriveView setShowTurnArrow:YES]; // 是否显示转向箭头,默认YES
        [self.aDriveView setShowCrossImage:NO]; // 是否显示路口放大图,默认YES
        [self.aDriveView setShowMoreButton:NO]; // 是否显示更多按钮,默认YES
        [self.aDriveView setShowTrafficBar:YES]; // 是否显示路况光柱,默认YES
        [self.aDriveView setShowUIElements:YES]; // 是否显示界面元素,默认YES
        [self.aDriveView setShowTrafficButton:YES]; // 是否显示实时交通按钮,默认YES
        [self.aDriveView setShowTrafficLayer:NO]; // 是否显示实时交通图层,默认YES
        [self.aDriveView setShowBrowseRouteButton:YES]; // 是否显示全览按钮,默认YES
        //            [self setCameraDegree:60];
        [self.aDriveView setMapZoomLevel:12];
        
    }else{
        
        self.aDriveView.showUIElements = NO;
        self.aDriveView.showTrafficLayer = NO;
        [self.aDriveView setShowCamera:NO];
        [self.aDriveView setCameraDegree:0];
//        [self.aDriveView setCarCompassImage:[DataUtility createImageWithColor:[UIColor clearColor]]];
        self.aDriveView.trackingMode = AMapNaviViewTrackingModeCarNorth;
        self.aDriveView.showMode = AMapNaviDriveViewShowModeCarPositionLocked;
        self.aDriveView.showGreyAfterPass = YES;
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.aDriveView.logoCenter = CGPointMake(self.aDriveView.right - self.aDriveView.logoSize.width * 0.5 - 10, self.aDriveView.bottom - self.aDriveView.logoSize.height * 0.5 - 10);
}
@end
